{block name="table"}
<div class="layui-tab layui-tab-card">
  <div class="layui-tab-content">
    {include file='/warehouse/warehouse_location/location_search'}
    <table id="LocationTable" data-url="{:sysuri('')}" data-target-search="form.form-search"></table>
  </div>
</div>
{/block}

{block name="script"}
<script>
  $(function () {
    let ids = {$ids};
    $('#LocationTable').layTable({
      toolbar: '#location_toolbarDemo',
      where:{'id':ids},
      even: true, height: 'full',
      sort: {field: 'sort', type: 'desc'},
      cols: [[
        {field: 'warehouse_c_name', title: '{:lang("仓库名称")}', align: 'center', minWidth: 120 },
        {field: 'location_code', title: '{:lang("货架名称")}', align: 'center', minWidth: 120 },
        {field: 'shelves_code', title: '{:lang("货架编号")}', align: 'center', minWidth: 120},
        {field: 'inventory_capacity', title: '{:lang("库存容量")}', align: 'center', minWidth: 120 },
        {field: 'shelves_type', title: '{:lang("货架类型")}', align: 'center', minWidth: 120 },
        {field: 'status', title: '{:lang("类型")}', align: 'center', minWidth: 120 },
        {field: 'sort', title: '{:lang("排序")}', align: 'center', minWidth: 120 },
        {field: 'create_at', title: '{:lang("添加时间")}', align: 'center', minWidth: 150, sort: true},
        {toolbar: '#location_toolbar', title: '{:lang("操作面板")}', align: 'center', width: 140, fixed: 'right'}
      ]]
    });

    // 单元格工具事件
    layui.table.on('tool(LocationTable)', function(obj){
      var data = obj.data; // 得到当前行数据
      var layEvent = obj.event; // 获得元素对应的 lay-event 属性值

      // 根据 lay-event 的值执行不同操作
      if(layEvent === 'print_location'){ //打印
        $.ajax({
          url: '{:url("print_location")}',
          type: 'post',
          dataType: "json",
          data: {id: data.id},
          beforeSend:(res)=>{indexload = layer.load(3, {shade: [0.1,'#fff']});},  //0.1透明度的白色背景
          complete:(res)=>{layer.close(indexload);},
          success: function (res) {
            if(res.code == 1){
              //初始化打印插件
              hiprint.init();
              // 打印模板
              let json = {"panels":[{"index":0,"height":40,"width":80,"paperHeader":-16.5,"paperFooter":113.38582677165356,"printElements":[{"options":{"left":51,"top":13.5,"height":9.75,"width":120,"field":"location_code","testData":"CC-33-1-1","fontSize":21.75,"fontWeight":"bolder","textAlign":"center"},"printElementType":{"type":"text"}},{"options":{"left":37.5,"top":37.5,"height":31.5,"width":148.5,"field":"location_code","testData":"CC-33-1-1","textType":"barcode","hideTitle":true},"printElementType":{"type":"text"}},{"options":{"left":51,"top":84,"height":9.75,"width":120,"field":"location_code","testData":"CC-33-1-1","fontSize":15,"fontWeight":"bold","textAlign":"center"},"printElementType":{"type":"text"}}],"paperNumberLeft":196,"paperNumberTop":91,"paperNumberDisabled":true}]}

              // 打印渲染数据
              let jsonData = res.data.jsonData;

              // 实例化并打印
              var hiprintTemplate = new hiprint.PrintTemplate({ template:  json});
              hiprintTemplate.print(jsonData);
            }
          }
        });
      }
    });
  });
</script>
<script type="text/html" id="location_toolbar">
  <!--  {if auth("location_edit")}-->
  <a class="layui-btn layui-btn-xs" data-event-dbclick data-title="{:lang('编辑')}" data-modal='{:url("location_edit")}?id={{d.id}}'>{:lang('编 辑')}</a>
  <!--  {/if}-->
  <!--{if auth('print_region')}-->
  <a lay-event="print_location" class='layui-btn layui-btn-xs layui-btn-primary'>{:lang('打印')}</a>
  <!--{/if}-->
</script>
{/block}
